package com.leetcode.binarytree;

public class MinimumDifference {

    private int res = Integer.MAX_VALUE;

    private TreeNode pre = null;

    public int getMinimumDifference(TreeNode root) {
        dfs(root);
        return res;
    }

    public void dfs(TreeNode root){
        if(root == null){
            return;
        }
        dfs(root.left);
        if(pre != null){
            res = Math.min(res, root.val - pre.val);
        }
        pre = root;
        dfs(root.right);
    }
}
